package demo01

import (
	"debug/plan9obj"
	"fmt"
)


type Command interface{
	Execute()
}

type StartCommand struct{
	mb *MotherBoard
}
// 构造
func NewStartCommand(mb *MotherBoard) *StartCommand{
	return &StartCommand{
		mb:mb
	}
}

// 实现
func (c *StartCommand) Execute(){
	c.mb.Start()
}

// 第二个结构体和第一个结构体都有公用的方法
type RebootCommand struct{
	mb *MotherBoard
}

func NewRebootCommand(mb *MotherBoard) * RebootCommand{
	return &RebootCommand{
		mb:mb,
	}
}

// 和公用的实例
func (c *RebootCommand) Execute(){
	c.mb.Reboot()
}

type MotherBoard struct{}

func (*MotherBoard)Start(){
	fmt.Println("sys starting")
}

func (*MotherBoard)Reboot(){
	fmt.Println("sys rebooting")
}

type Box struct{
	button1 Command
	button2 Command
}

func NewBox(button1, button2, Command) *Box{
	return &Box{
		button1: button1,
		button2: button2,
	}
}

func (b *Box)PressButton1(){
	b.button1.Execute()
}
func (b *Box)PressButton2(){
	b.button2.Execute()
}

// -----------------------once again---------------------------

// 命令设计模式 

type Command_1 interface{
	Execute_1()
}

type StartCommand_1 struct{
	mb MotherBoard_1
}

func NewStartCommand_1(mb MotherBoard_1) *StartCommand_1{
	return &StartCommand_1{
		mb: mb,
	}
}

func(s *StartCommand) Execute_1(){
	s.mb.Start()
}

type StopCommand_1 struct{
	mb *MotherBoard_1
}

func NewStopCommand_1(mb MotherBoard_1) *StopCommand_1{
	return &StopCommand_1{
		mb: mb,
	}
}
func(s *StopCommand_1) Execute_1(){
	s.mb.Stop()
}

type MotherBoard_1 struct{}

func (m *MotherBoard_1)Start(){
	fmt.Println("starting")
}

func (m *MotherBoard_1)Stop(){
	fmt.Println("stoping")
}

type Box1 struct{
	button1 Command_1
	button2 Command_1
}

func NewBox1(button1, button2 Command_1) *Box1{
	return &Box1{
		button1: button1,
		button2: button2,
	}
}

func (b *Box1)Execute(){
	b.button1.Execute_1()
	b.button2.Execute_1()
}